﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using IPTV.DBUtility;

/// <summary>
///首页广告图片
/// </summary>
public class ADpicDao
{
	public ADpicDao()
	{
    
	}

    public List<me_p_recommend_config>  getAdPic()
    {
        string sql = " select m.picture , m.linkrule from me_p_recommend_config m where m.categorykind = 'CK_TGSG_HOMEPAGE_AD' "+
                     " and m.is_publish = 1 order by m.displayorder asc ";

        List<me_p_recommend_config> picList = new List<me_p_recommend_config>();
        try
        {
            MySqlDataReader reader = MySQLHelper.ExecuteReader(MySQLHelper.CONNECTION_STRING, sql, null);

            while (reader.Read())
            {
                me_p_recommend_config pic = new me_p_recommend_config();
                pic.Picture = reader[0].ToString();
                pic.Linkrule = reader[1].ToString();
                picList.Add(pic);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("find AD pic error.");
        }

        return picList;
    }


    public me_p_recommend_config getAdPic(string categorykind)
    {
        string sql = " select m.picture , m.linkrule , m.entity_id , m.entity_grade , m.entity_subject , m.title from me_p_recommend_config m where m.categorykind = @categorykind " +
                     " and m.is_publish = 1 order by m.displayorder asc ";

        MySqlParameter[] parms = new MySqlParameter[] 
        { 
            new MySqlParameter( "@categorykind" , MySqlDbType.VarChar, 30 )
        };

        parms[0].Value = categorykind;
        me_p_recommend_config pic = null;
        try
        {
            MySqlDataReader reader = MySQLHelper.ExecuteReader(MySQLHelper.CONNECTION_STRING, sql, parms);

            while (reader.Read())
            {
                pic = new me_p_recommend_config();
                pic.Picture = reader[0].ToString();
                pic.Linkrule = reader[1].ToString();
                pic.Entity_id = reader[2].ToString();
                pic.Entity_grade = reader[3].ToString();
                pic.Entity_subject = reader[4].ToString();
                pic.Title = reader[5].ToString();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("find AD pic error.");
        }

        return pic;
    }
}